package com.tom;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class MemberController
 */
public class MemberController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private String userid;
	private String pw1;
	private String pw2;
	private String email;
    ArrayList<String> ErrorMsg;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MemberController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		userid = request.getParameter("id");
		pw1 = request.getParameter("pw1");
		pw2 = request.getParameter("pw2");
		email = request.getParameter("email");
		Member m = new Member(userid, pw1, pw2, email);
		
		
		if (userid == null) {
			ErrorMsg.add("請輸入正確帳號");
		} else if (!pw1.equals(pw2)) {
			ErrorMsg.add("請確認密碼是否相符");
		} else if (email.indexOf("@") == -1) {
			ErrorMsg.add("請輸入正確格式的 E-Mail");
		} else {
			m.add(userid, pw1, pw2, email);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
